package cn.itcast.hotel.Listenner;

import cn.itcast.hotel.Contants.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MqListenner {
    @Autowired
    IHotelService hotelService;
    @RabbitListener(queues = MqConstants.QUEUE_HOTEL_INSERT)
    public void listenhotelinsert(Long id){
        try {
            hotelService.insertorupdatehotel(id);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    @RabbitListener(queues = MqConstants.QUEUE_HOTEL_DELETE)
    public void listenhoteldelete(Long id){
        try {
            hotelService.deletehotel(id);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
